<?php
/**
 * The world of warcraft armory library was created by Marc Binder. The called
 * product will be deployed by Tof Technologies, Germany. All sources contain to 
 * the New BSD Licence. Self created extensions can be contained in the hall of 
 * fame. So the community has the chance to get a overview of all parsers and
 * handlers, which are really effective.
 * 
 * Get more informations:
 * http://code.google.com/p/warcraftarmory/
 * 
 * @author      Marc Binder <marcandrebinder@gmail.com>
 * @copyright   (c) Tof Technologies, Germany - 2010
 * @license     New BSD Licence
 * @package     Wow_Armory
 * @version     $Id$
 */

/**
 * Wow_Armory_Handler_Default
 * 
 * @category    Wow_Armory
 * @package     Handler
 * @subpackage  Default
 * @example     n/A
 */
class Wow_Armory_Handler_Default extends Wow_Armory_Core_Handler_Abstract
{
    
    const TWOONTWO = '2on2';
    const THREEONTHREE = '3on3';
    const FIVEONFIVE = '5on5';
    
    /**
     * Creates the object.
     * 
     * @return void
     */
    public function __construct()
    {
        Wow_Armory_Parse_Result_Need::set(self::CHARACTER);
    }
    
    /**
     * Parse the default handler.
     * 
     * @return Wow_Armory_Handler_Default
     */
    public function parse()
    {
        $result = Wow_Armory_Parse_Result_Registry::get(self::CHARACTER);
        
        $characterInfo = $result['characterInfo'];
        
        $global    = (array) $characterInfo;
        $character = (array) $global['character'];
        $global    = (array) $character['@attributes'];
        $this->_toResults($global);
        
        $details      = (array) $characterInfo;
        $characterTab = (array) $details['characterTab'];
        
        $this->_parseTalentSpecs((array) $characterTab['talentSpecs']);
        $this->_parseBars((array) $characterTab['characterBars']);
        $this->_parseBaseStats((array) $characterTab['baseStats']);
        
        $arena = (array) $character['arenaTeams'];
        $arena = (array) $arena['arenaTeam'];
        
        if (count($arena) > 0) {
            $this->_parseArena($arena);
        }
        
        return $this;
    }
    
    /**
     * Parse the base stats.
     * 
     * @param  array $stats
     * @return void
     */
    protected function _parseBaseStats(Array $stats)
    {
        foreach ($stats as $key => $stat) {
            $data = (array) $stat;
            $data = $data['@attributes'];
            
            foreach ($data as $i => $item) {
                $var = $key . ucfirst($i);
                $this->$var = $item;
            }
        }
    }
    
    /**
     * Parse the bars.
     * 
     * @param  array $bars
     * @return void
     */
    protected function _parseBars(Array $bars)
    {
        $health = (array) $bars['health'];
        $health = (array) $health['@attributes'];
        $this->healthBar = $health['effective'];
        
        $second = (array) $bars['secondBar'];
        $second = (array) $second['@attributes'];
        $this->secondBar = $second['effective'];
    }
    
    /**
     * Parse the talent specs.
     * 
     * @param  array $talents
     * @return void
     */
    protected function _parseTalentSpecs(Array $talents)
    {
        $specs = (array) $talents['talentSpec'];
        
        if (count($specs) <= 0) {
            return false;
        }
        
        foreach ($specs as $spec) {
            $item = (array) $spec;
            $item = $item['@attributes'];
            
            if (isset($item['active'])
                && $item['active'] == '1'
            ) {
                $id = 'first';
            } else {
                $id = 'second';
            }
            
            $this->_results['specs'][$id] = 
                new Wow_Armory_Handler_Element_Default_Spec($item);
            
        }
    }
    
    /**
     * Returns the arena team size as a string.
     * 
     * @param string $size
     * @return string
     */
    protected function _parseArenaTeamSize($size)
    {
        switch ($size) {
                    
            case '2':
                return self::TWOONTWO;
                break;
                
            case '3':
                return self::THREEONTHREE;
                break;
                
            case '5':
                return self::FIVEONFIVE;
                break;
            
        }
    }
    
    /**
     * Parse an arena team.
     * 
     * @param array $teams
     */
    protected function _parseArena(Array $teams)
    {
        if (isset($teams['@attributes'])) {
            $teamSize = $this->_parseArenaTeamSize(
                $teams['@attributes']['teamSize']
            );
            $this->_results['arenaTeams'][$teamSize] = 
                    new Wow_Armory_Handler_Element_Default_Arena_Team($teams['@attributes']);
        } else {
            foreach ($teams as $team) {
                $teamSize = $this->_parseArenaTeamSize($team['teamSize']);
                $array   = (array) $team;
                $emblem  = (array) $array['emblem'];
                $emblem  = $emblem['@attributes'];
                $members = (array) $array['members'];
                $data    = $array['@attributes'];
                $this->_results['arenaTeams'][$teamSize] = 
                    new Wow_Armory_Handler_Element_Default_Arena_Team(
                        $data,
                        new Wow_Armory_Handler_Element_Default_Arena_Team_Emblem($emblem),
                        $members
                    );
            }
        }
    }
    
    /**
     * Returns the battle group.
     * 
     * @return string
     */
    public function getBattleGroup()
    {
        return $this->battleGroup;
    }
    
    /**
     * Returns the char url.
     * 
     * @return string
     */
    public function getCharUrl()
    {
        return $this->charUrl;
    }
    
    /**
     * Returns the class name.
     * 
     * @return string
     */
    public function getClass()
    {
        return $this->class;
    }
    
    /**
     * Returns the class id.
     * 
     * @return string
     */
    public function getClassId()
    {
        return $this->classId;
    }
    
    /**
     * Returns the class url.
     * 
     * @return string
     */
    public function getClassUrl()
    {
        return $this->classUrl;
    }
    
    /**
     * Returns the faction.
     * 
     * @return string
     */
    public function getFaction()
    {
        return $this->faction;
    }
    
    /**
     * Returns the faction ids.
     * 
     * @return string
     */
    public function getFactionId()
    {
        return $this->factionId;
    }
    
    /**
     * Returns the gender.
     * 
     * @return string
     */
    public function getGender()
    {
        return $this->gender;
    }
    
    /**
     * Returns the gender id.
     * 
     * @return string
     */
    public function getGenderId()
    {
        return $this->genderId;
    }
    
    /**
     * Returns the guild name.
     * 
     * @return string
     */
    public function getGuildName()
    {
        return $this->guildName;
    }
    
    /**
     * Returns the guild url.
     * 
     * @return string
     */
    public function getGuildUrl()
    {
        return $this->guildUrl;
    }
    
    /**
     * Returns the last modified date.
     * 
     * @return string
     */
    public function getLastModified()
    {
        return $this->lastModified;
    }
    
    /**
     * Returns the level.
     * 
     * @return string
     */
    public function getLevel()
    {
        return $this->level;
    }
    
    /**
     * Returns the name.
     * 
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
    
    /**
     * Returns the points.
     * 
     * @return string
     */
    public function getPoints()
    {
        return $this->points;
    }
    
    /**
     * Returns the prefix.
     * 
     * @return string
     */
    public function getPrefix()
    {
        return $this->prefix;
    }
    
    /**
     * Returns the race.
     * 
     * @return string
     */
    public function getRace()
    {
        return $this->race;
    }
    
    /**
     * Returns the race id.
     * 
     * @return string
     */
    public function getRaceId()
    {
        return $this->raceId;
    }
    
    /**
     * Returns the realm.
     * 
     * @return string
     */
    public function getRealm()
    {
        return $this->realm;
    }
    
    /**
     * Returns the suffix.
     * 
     * @return string
     */
    public function getSuffix()
    {
        return $this->suffix;
    }
    
    /**
     * Returns the title id.
     * 
     * @return string
     */
    public function getTitleId()
    {
        return $this->titleId;
    }
    
    /**
     * Returns the arena teams.
     * 
     * @return array
     */
    public function getArenaTeams()
    {
        return $this->arenaTeams;
    }
    
    /**
     * Gets an arena team by type.
     * 
     * @param  string $type
     * @return Wow_Armory_Handler_Element_Default_Arena_Team
     */
    public function getArenaTeam($type)
    {
        if ($type != self::TWOONTWO
            && $type != self::THREEONTHREE
            && $type != self::FIVEONFIVE
        ) {
            return false;
        }
        
        return $this->_results['arenaTeams'][$type];
    }
        
    /**
     * Returns all specs.
     * 
     * @return array
     */
    public function getSpecs()
    {
        return $this->specs;
    }
    
    /**
     * Gets the first spec.
     * 
     * @return Wow_Armory_Handler_Element_Default_Spec
     */
    public function getFirstSpec()
    {
        return $this->_results['specs']['first'];
    }
    
    /**
     * Gets the second spec.
     * 
     * @return Wow_Armory_Handler_Element_Default_Spec
     */
    public function getSecondSpec()
    {
        return $this->_results['specs']['second'];
    }
    
    /**
     * Returns the health bar as a string.
     * 
     * @return string
     */
    public function getHealthBar()
    {
        return $this->healthBar;
    }
    
    /**
     * Returns the second bar as a string.
     * 
     * @return string
     */
    public function getSecondBar()
    {
        return $this->secondBar;
    }
    
    /**
     * Get the strength attack value.
     * 
     * @return string
     */
    public function getStrengthAttack()
    {
        return $this->strengthAttack;
    }
    
    /**
     * Get the strength base.
     * 
     * @return string
     */
    public function getStrengthBase()
    {
        return $this->strengthBase;
    }
    
    /**
     * Get the strength block value.
     * 
     * @return string
     */
    public function getStrengthBlock()
    {
        return $this->strengthBlock;
    }
    
    /**
     * Get the strength effective value.
     * 
     * @return string
     */
    public function getStrengthEffective()
    {
        return $this->strengthEffective;
    }
    
    /**
     * Get the agility armor value.
     * 
     * @return string
     */
    public function getAgilityArmor()
    {
        return $this->agilityArmor;
    }
    
    /**
     * Get the agility attack value.
     * 
     * @return string
     */
    public function getAgilityAttack()
    {
        return $this->agilityAttack;
    }
    
    /**
     * Get the agility base value.
     * 
     * @return string
     */
    public function getAgilityBase()
    {
        return $this->agilityBase;
    }
    
    /**
     * Get the agility crit hit percent value.
     * 
     * @return string
     */
    public function getAgilityCritHitPercent()
    {
        return $this->agilityCritHitPercent;
    }
    
    /**
     * Get the agility effective value.
     * 
     * @return string
     */
    public function getAgilityEffective()
    {
        return $this->agilityEffective;
    }
    
    /**
     * Get the stamina base value.
     * 
     * @return string
     */
    public function getStaminaBase()
    {
        return $this->staminaBase;
    }
    
    /**
     * Get the stamina effective value.
     * 
     * @return string
     */
    public function getStaminaEffective()
    {
        return $this->staminaEffective;
    }
    
    /**
     * Get the stamina health.
     * 
     * @return string
     */
    public function getStaminaHealth()
    {
        return $this->staminaHealth;
    }
    
    /**
     * Get the stamina pet bonus.
     * 
     * @return string
     */
    public function getStaminaPetBonus()
    {
        return $this->staminaPetBonus;
    }
    
    /**
     * Get the intellect base value.
     * 
     * @return string
     */
    public function getIntellectBase()
    {
        return $this->intellectBase;
    }
    
    /**
     * Get the intellect crit hit percent.
     * 
     * @return string
     */
    public function getIntellectCritHitPercent()
    {
        return $this->intellectCritHitPercent;
    }
    
    /**
     * Get the intellect effective value.
     * 
     * @return string
     */
    public function getIntellectEffective()
    {
        return $this->intellectEffective;
    }
    
    /**
     * Get the intellect mana.
     * 
     * @return string
     */
    public function getIntellectMana()
    {
        return $this->intellectMana;
    }
    
    /**
     * Get the intellect pet bonus.
     * 
     * @return string
     */
    public function getIntellectPetBonus()
    {
        return $this->intellectPetBonus;
    }
    
    /**
     * Get the spirit base value.
     * 
     * @return string
     */
    public function getSpiritBase()
    {
        return $this->spiritBase;
    }
    
    /**
     * Get the spirit effective value.
     * 
     * @return string
     */
    public function getSpiritEffective()
    {
        return $this->spiritEffective;
    }
    
    /**
     * Get the spirit health regen.
     * 
     * @return string
     */
    public function getSpiritHealthRegen()
    {
        return $this->spiritHealthRegen;
    }
    
    /**
     * Get the spirit mana reg.
     * 
     * @return string
     */
    public function getSpiritManaRegen()
    {
        return $this->spiritManaRegen;
    }
    
    /**
     * Get the armor armor base value.
     * 
     * @return string
     */
    public function getArmorBase()
    {
        return $this->armorBase;
    }
    
    /**
     * Get the armor effective value.
     * 
     * @return string
     */
    public function getArmorEffective()
    {
        return $this->armorEffective;
    }
    
    /**
     * Get the armor percent.
     * 
     * @return string
     */
    public function getArmorPercent()
    {
        return $this->armorPercent;
    }
    
    /**
     * Get the armor pet bonus.
     * 
     * @return string
     */
    public function getArmorPetBonus()
    {
        return $this->armorPetBonus;
    }
    
}